﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using T4MVCGen.Core.Persistence;

namespace T4MVCGen.Core
{
    public class EnvSettings
    {


        private const string AppDataFolder = "App_Data";
        public string BaseDir { get; set; }
        public string SvnIP { get; set; }
        public string AppPoolName { get; set; }
        public string ProductionDir { get; set; }
        public int DbType { get; set; }
        public string Server { get; set; }
        public string Database { get; set; }
        public int AuthenticationType { get; set; }
        public string Login { get; set; }
        public int CreateMultipleFiles { get; set; }
        public string Project { get; set; }
        public string Namespace { get; set; }
        public string DaoSuffix { get; set; }
        public string DtoSuffix { get; set; }
        public string OutputDirectory { get; set; }

        private IJsonRepository<EnvSettings, string> _repository { get; set; }

        public EnvSettings()
        {

        }

        public void LoadSettings()
        {
            var _Instance = getRepository().Single<EnvSettings>("settings");
            BaseDir = _Instance.BaseDir;
            SvnIP = _Instance.SvnIP;
            AppPoolName = _Instance.AppPoolName;
            ProductionDir = _Instance.ProductionDir;
            DbType = _Instance.DbType;
            Server = _Instance.Server;
            Database = _Instance.Database;
            AuthenticationType = _Instance.AuthenticationType;
            Login = _Instance.Login;
            CreateMultipleFiles = _Instance.CreateMultipleFiles;
            Project = _Instance.Project;
            Namespace = _Instance.Namespace;
            DaoSuffix = _Instance.DaoSuffix;
            DtoSuffix = _Instance.DtoSuffix;
            OutputDirectory = _Instance.OutputDirectory;

        }

        public void SaveSettings()
        {
            getRepository().Save<EnvSettings>(this, "settings");
        }

        private IJsonRepository<EnvSettings, string> getRepository()
        {
            if (_repository == null)
            {
                return new JsonRepository<EnvSettings, string>();
            }
            else
                return _repository;
        }


    }
}
